package org.intrasearch.spider;

import org.intrasearch.core.ArtifactId;
import org.intrasearch.core.DirectoryArtifactImpl;
import org.intrasearch.core.FileArtifactImpl;
import org.intrasearch.core.ResourceArtifact;

import java.util.Collections;

public class Artifacts
{
    public static ResourceArtifact<? extends ResourceArtifact> createFromVirtualFile(VirtualFile file, ArtifactId parentDirId)
    {
        if (!file.isDirectory())
        {
            return new FileArtifactImpl(file.getName(), file.length(), Collections.singleton(file.getURL().toString()));
        }
        return new DirectoryArtifactImpl(file.getName(), Collections.singleton(file.getURL().toString()), Collections.<ArtifactId>emptySet(), parentDirId);
    }
}
